Made this a tiny bit more flexible, but I'm still not using a heap, as I think might be best.