mildly cleaned up. curious if i can rewrite the pSg_ functionally.