Changed the position of if condition