tests and clean up. need to fix optimiser