Removed superfluous code, clean up

Removed some unnecessary parts and restructured the whole of the code
to be more legible.