see comment about setting the flags below