replacing button press event with flags