Cleaned up a TON of repeated code with Scala