minor refactoring, exception handling in progress