Cleaned up some of the logic gates. Inserted a missing "fi".
Improved the logging functions on the script.