tidied code and chopped the cruft