Cleaned up, refactored, tested

Working as of 25/06/2014