finalized refactor