Improved error messages
Refactored