more refactoring with error codes and clean unmounting of mounts