Fix for better compatibility with different heapq implementations