Added templates. Moved functionality out of models