add comments and explain heap and stack memory allocation