code refactor for unsubscribe