small changes, fixed a common length invalid access error