more elegant error handling for gate