Bug fixes and tweaks