Added Scala pattern matching