add length
fixed some bugs