edits from Hongkai's code review