First version of complete script. Changed sleeps to 0.5 seconds.