I suggest going with your "firstfunction()", but get rid of the apparently spare "wait()"s inside some of the if's, and just have a single one inside the loop at its end.
"There is no fate but what WE make." - CEO Cyberdyne Systems Corp. A8.30.5 Commercial