Improved collapse/expand graphs code and performance