fixed calling order of callbacks