Fixed length calculation.
Added relevant tests.