Various improvement, based on language builtins and PEP8, fix unreachable code with contextlib.