homework 3 - adding flag logic