lots of messing around. sorry for the bloat