Fixed error handling in listener removal logic.