Fixing nil errors, when elements are empty