Code cleanup
Improved error handling
Fixed checking applications for availability