Lots of small fixes to the core engine and the samples.