fixes binary heap issues and adds tests