fix uid and gid conversion
fix cleanup after errors
fix inconsistent api