Minor refactoring, exception handling