code review changes 2. clear references when attachment is deleted, and insert preview reference when attachment is clicked.  use foreach, and other cleanup