some improvement on the post on Scala pattern matching