improved error handling in models