I'm not a huge fan of this entire structure. It can probably be trimmed down to 1 function with 3-4 lines of code