Bug fix and tweaks