optimization function update and tests