move to rustc-serialize
add more robust error handling