Refactored code a little bit.

Made the source easier to read.