Started working on splitting the thing into functions.