add cancellation function and ficed some bugs