fixed NullpointerException

This fix should solve the NullPointerException occurring with odd number of items.