Fix close() bug