implemented rough version of code which constitutes a single step of optimization