Bug and efficency fixes.