modificating close() function