lots of bug fixes