refactor almost done