tidied up code ready for v1.2