some structural changes, plus removing unneeded code