Removed some legacy code and improved readability of main script.