Finished new refactor, currently untested