Fixing bug of spinner function