Needs a refactor.