This is the version that Charlie wrote unit tests for and made correct