changed way of setting last opened context to db: