Tidy up code and remove unused files