functioning fourheap. comments and style to be fixed