Cleaned up exception handling according to best practices