Fix bug in sub-graph preparations