adding error catching and simple logging