MDL-40987, improvaing repagination and unittests