now uses global state, updated docs, and tests