More logic improvement up to first move, added helper 'inArray' function