Fields become corrupt when using conditional statement