modified Heap for ex 4 and readability