Refactor and simplify remove algo