Use getTable to get table name.

Use Magento's getTable instead of hardcoding the string.
Re-ordered SQL Statements

Moved the functions that cannot be run twice to the
end of the script, so that if something goes wrong
early on in the script, it should be able to run a second
time without major problems.