General bug fixes and tweaks