Test refactoring, no functional changes but adding catch blocks for clean shutdown on failures