correcting range in loop (range(len(a)))