Move runcommand loop to separate function