made qs function more efficient