some new stuff from rob plus other things
removed lots of unnecessary code