optimisations and fixed tests