Shift handle_error and get_limit into utils and fix formatting/naming issues