Fixed some performance bugs.