Fixed the misinterpretation of length parameter, which caused some unit tests failed.