refactor onCancel method