Pulling kim's new flag code

Pulling this to a branch for further testing/reading.