Fix callback hell and configurable end callback