implement nth functionality