tidied up code base for use in thesis