Some refactoring and code reuse

Added two more cases as instructed on Piazza
1. After cookie expires, if user does a replace operation, create new
session and replace the text
2. Ensured version no. mess-up due to the URL redirect in post.
3. After cookie expires and user does a refresh, instead of logging
out, create a new cookie for him and direct him to home page.