various bug fixes and tweaks