optimization written and tested