Better exception handling
Refactoring