Updated with 0.6 code from rustoxide submission