added pieces of missing code from template