Added DAG class and various minor improvements