bunch of bug-fixes