Using 'with' statement and cleaning code using pylint.