Refactor removal of pending requests into a function