fixed iteration to optimal
added checks