lots of fixes for sanity