Various optimisatios, tweaks and fixes to files