Improve the code for Spark 0.9 and Scala 2.10