better error handling ux and some refactoring