Bug fixes, and tweaks