Minor bug fixes to improve speed.