[SPARK-1837] code refactoring