Fix sessions not being saved after some exceptions
Split saveSession method to save only on terminate
Clean up a few things.