added context manager and updated test cases