More refactoring and commenting

Not great but I don't feel like doing any more