refactor how we work with documents a bit