Starting to refactor this monstrosity