fix bad conversion
robustify code