Add shorten function and tests.