Refactor session handling

Make PSR-2 compatible