added some failchecking