Added a little sturdier error recovery/exception handling