added safeClose() to common class