Closeable support

The same as #532 but with tests :)