Added comments to source + minor fixes. Preprocessing script now sorts by ref.  (#1)