changed variable check from routine to function in order to return value