Fix pattern matching order