General code fixes / test fixes