bunch of sanity code corrections.