Added expiry handling
Fix flushing problem