sanity error fixed and some tidying up work done