Cleaning up some hacky stuff and making it more extensible so we can reuse it if we need to