rearranged code
revamped string search