changed closeable variable to not be a global value, instead made a function