Refactored code to streamline things a bit.