Fix length calculation bug so that hash works for all values