implement __enter__ and __exit__