added code for take the last entry