Reviewed and corrected error handling
Pre-release refactoring