SPARK-2761 fix documentation, reorder code