Added code for deleteKey() to handle removing ends.