refactoring and scalafication