Improved tempid usage on database.