ReplaceTables: Fix null checks