Refactoring the large annotate method, and close the connection with close_and_discard