Put DAG creation in a separate function, added more fallback paths.