implemented most of the template