working on close function