modified to take in 0 as number of entries and not die