Close application context on exit. Added formatterand save on exit hooks