added flexible heap management to host stack, fixed critical section issues