Added fallback logic if  is not correctly set.