fixed all the nasty bugs