Fixed issue #4 by checking if an item is defined before trying to sort
it.