bug fixes on Scala match error