changed some error handling and templates