improved code clarity in ViewModel, added error handling