Split monolithic loop out into more functions. You know, the basics.