Reworked session logic