This feels like a large function with a lot going on in it.