Various refactoring and scaladoc