refactor, more robust flag propagation