Refactor session and hook