Escaped characters fixed
iterate through string byte by byte without splitting
replaced whitespace detecting preg expression with simple comparison