some nasty bugs fixed