changes optim() and upper lower func on generic length