refactor unmanaged_password code with error checking