adding comments and error handling