fixed a bug for grouping nodes by layers and added comments