Fix some inefficient code.