Added support for heap.
Changed main to a separate file