cleaned up error handling, comments