Add preventclosing as a function to be dinamically defined, some minor refactoring to support not losing bindings