Modified heap and fixed memory block related bugs