A general comment about this file: This file now contains stuff needed for the "new" api and stuff needed for the "old" api, but it's impossible to tell which is which. To make the code more understandable to someone trying to learn it, it might be helpful to split the two apis out into separate files, with some comments in each file explaining the difference.