added cycle checking to graph model