some refactory, added sleep time