optimization not quite working yet