cleaner close() implementation