loop in function needs to start at 0, not 1