modified shorten function