refactory session and env