Added missing variable initialisation and replaced some str != "" with !str.empty()