Fix state aggregation and bug in graph layout