(part of) code for closing