refactor and reorganize