adds additional error checking and fixes bug where uid was set which prevented gid being set