reimplemented the analysis as a context manager too