refactored to remove read function and separate tag removal process as a separate function