write better error handling for main