changed algorigthm of optimized()