Tidy up, tests, profiling fixes.