fixed stuid()/setgid() and error handling