some tidying up, extended with optimizers