Cleaned up Spark code, added some comments