Refactor: added different closing mechanisms based on available open
resources