Refactor and reorganize