NULL case check added for peek()