reorganize and refactor