Do not check second if statement at every run of function