bug fixes and performance tweaks