added correct error handling to template