Clean up code. Documentation comments added. Format of output changed.