SPARK-2632, SPARK-2576. Fixed by only importing what is necessary during class definition.

This can be reworded, but I was out of ideas.