fixed bug with incorrect gpi array sorting