Potential Scala solution