Move template appending into function, add test coverage