refactor almost complete;