Tidying up code structure.

Making things easier to read/follow.