General fixes and optimalisations.