Added recursive graph reduction function. fixes #18