finished templated and added additional code