implemented template unit tests - refactored some code