Integrated if to work more correctly