Added error handling, re-factored code, UI change