implementing functional queue