Major code refactor.