Better pattern matching + Tail recursion for merge