switch code to scala, compile it