added encoding of % and optimized using array