Split code up into functions and began to write optimization capabilities