fixes crashing if close is called out of seq.