fixed nasty bugs