Improved StabilizeTask function.