add call of close() in sleep()