refactored Scala into object and class