Fix order of pattern matching for apply