Some small performance tweaks and a bug fix.