fixed read error, unsure on flag logic