Commented and cleaned up

Functionality much the same but cleaned up a little and commented so at
least I can understand it come tomorrow.