Made the changes Carl suggested: Used arrays for Gp instead of for loops and simplified whole script