fixed if logic