ported MainController from java to scala