solved some nasty bugs