moved session code to template file