refactor code and put in random time to sleep