Refactoring & begin improve error handling