fixed a bug for sleeping