fixed backwards if logic