lots of refactoring, application is now a lot more resilient to crashes