Placed the if block at the wrong place.