Fixed bug when multiple callbacks are involved in one function call