code linked to DipyDoc's completely rewritten