welp, this needs testing. heapified most things