Fix some compatibility issues

- Use `String.charAt(index)` instead of array like syntax for browser compatibility.
- Use `Array.slice(index, length)` instead of `Array.slice(index)` for browser compatibility.