improve error catching & portability