Internal clean_session function

To be used in tests.
Fix a bug in set_config for session
Make sure file (get) and dirname(file) (set) exists
Fix a bug when reading from files
Add a couple of tests