Clear session data before writing the session

Session is written and then cleared, which leaves the session full
with all it's data. We need to clean the session and then write.