Switch to scala.

This should be easier to implement in scala since I'm more familiar with JVM.