length function updated (still need to be improved) @vjovanov