Rewrote some code to make it more efficient.