Fixed application shutdown and minor improvements