calculate g and p changed