collapse/expand algorithm, INCOMPLETE