fixed allocating from global heap and usage of prev pointers