General clean up of bits of code. Also started adding comments to all
code.