Improved handling, so that the longest key that fits is expanded.