reorganized dag for better readability
cleaned up code and added comments