Fixed the issue when p(1) and p(2)  when they exceeded index values