streamlined epoch sorting, plus some cleanup
merge Bob's lastest changes from master