added try and catch, saving errors to log