Updated the position of $state.go() so that user will only be redirected if operations are successful.