I reused the condition from the original code. I can scalaify it too.