Bug fixes and tweaking