bug fix and added optimum way.