Refactoring
Better error reporting