refactored solution to allow Scala solutions