Graph building failure, get rid of recursion