reused char array and change condition to make it faster