added some session stuff and error tracking