Moving some variable checks outside functions