Moved the if condition higher in the program