added checks for situations when all tables target other databases
fixed minor bugs