fix if statement

madmaxoft's code, slightly modified