tidied up code and removed unnecessary tests.