changed sleep function