Added generic tryLoop function for repeating command until success or timeout