add close() to the function