Added comments.
Added comments and whitespace.
Included changes in orientation to the distance metric.