including error message, and moving session_id reset outside of the conditional block