implemented a runWithSession mechanism