Being new to Scala, I'll bet this method can be written nicer