Replaced open/close calls with `with` statements