Remove dependence on optim module

With all functionality preserved. Pure renaming.