Tidied up code, removed unused sections.