added stopping boolean
moved safeClose() to Main class