Converted the main loop to p.Index
more modularization