added error functions and templates