I think this can be divided into a few top level functions as well.