Revert some unnecessary changes. Tidy up the code a bit