tweaked logic after implementing flags