misc corrections and optimisations