refactoring closure computation