Cleaned up Spark code, added comments