fix bug with running callback in next tick