Refactor almost working.