refactor totally