Neatened up Scala code