Simplified the code a little to make it more readable.