changes in close() method. Now it doesn't hangs when we close it