Refactored error handling, help display, and added comments