tidied up the code, removed obsolete code