freeze: simplify code and use with open()