fixes and added some failsafes