cleaned up working version with a minor bug. Sometimes a reader jumps in front of a writer.