misc changes and dgam function now has its own file