Done, and made the logic slightly more readable.