use a switch for proper error handling