Yet more lastInsertedId revamping. Third time's the charm.