add length, fix some bugs