Refactor code to function check exit none available program

a code we reuse quite often: as function