     backupTables boolean;
     cleanUpCodesTimeLimit int;
     cleanUpDateTimeLimit timestamp;
+    backupTable text;
+    cusrRecord record;
+
+tablesCursor CURSOR FOR SELECT tablename FROM pg_catalog.pg_tables WHERE schemaname = current_schema() AND
+tablename  IN ('idn_recovery_data');
 
 BEGIN
 

    batchCount := 1000;
    chunkCount := 1000;
    rowCount   := 0;
    cleanUpCodesTimeLimit := 1;
    cleanUpDateTimeLimit :=  timezone('UTC'::text, now()) - INTERVAL '1hour' * cleanUpCodesTimeLimit;
    RAISE NOTICE 'Cleanup time limit : %', cleanUpDateTimeLimit;

    IF (enableLog) THEN
        RAISE NOTICE 'WSO2_CONFIRMATION_CODE_CLEANUP() STARTED...!';

    -- ------------------------------------------
    -- BACKUP DATA
    -- ------------------------------------------
    Begin
        IF (backupTables)
        THEN
            OPEN tablesCursor;
            LOOP
                FETCH tablesCursor INTO cusrRecord;
                EXIT WHEN NOT FOUND;
                backupTable := cusrRecord.tablename||'_backup';

                EXECUTE 'SELECT count(1) from pg_catalog.pg_tables WHERE schemaname = current_schema() AND tablename =  $1' into rowcount USING backupTable;
                IF (rowcount = 1)
                THEN
                    EXECUTE 'DROP TABLE '||quote_ident(backupTable);
                END IF;

                EXECUTE 'CREATE TABLE '||quote_ident(backupTable)||' as SELECT * FROM '||quote_ident(cusrRecord.tablename);

            END LOOP;
            CLOSE tablesCursor;
        END IF;

    -- ------------------------------------------
    -- CLEANUP DATA
