Refactored the code a little, just to make it easier to follow (KISS).