more writeup, and refactor stack allocation