bunch of bug fixes