some bug fixes and tweaks