Refactored code a little.