Now with context manager
Applied @bathompso's patch to batch branch
Context manager FTW