Changed getOpti function