Finish refactoring this