.close() statements reordered