Various bug fixes and performance tweaks
Merge remote-tracking branch 'public/master'