implemented queue function