Added extra checking for whether we're in a transaction