use range instead of indexing