heap algorithms (untested), misc tweaks