Make some of the packages optional.
Fix formatting: Replace spaces with tabs.
Fix log output.
Refactor the code into multiple functions.