Fixes remaining problems with app termination