basically breaking up the code, and adding an if clause for efficiency.