if statement was messing things up