error handling and some session fix