changed -1 to n