Better thread collapser
Fix refmap creator