Fix with window not closing after search

Fixed search window not closing after searching resulting in invalid
string length error if searched again.