working alg for gpw