I think this section of the code would be worth some inline comments, it could be confusing to others reading your code for the first time how the callbacks work.