Made some code more efficient