should probably pull this up a level and make it take source doc as an argument for testability