convert callback function to struct of functions

See discussion
https://groups.google.com/forum/?hl=en&fromgroups=#!topic/mongoose-users/Ayp5pGxoM5E