refactored close