Reworked some of the code.