pid/gid mess improved

Not sure if dependencies are correct. please check.
fixed