Cleaned up the if statements and made they more scala-like