Fixed small bugs in logging and handle expiration logic. Bugzilla #312.