Refactoring session handling

* Refactoring to inject dependencies
* Make PSR-2 compatible