database access changed, removing of sessions added

The database is now fetched in subs to encapsulate this work.

Removeing session are added.