write optimization by moving byte iteration over strings into java land.