Refactored error/exception handling to separate method