length calculation only once
moved stuff