Fixed: duplicated logging statements

Logger was used before being setup. Logger setup moved before relevant
logging statements, and placed within `__name__ == "__main__"` block to
prevent the logger from being setup twice when main.py used as a
library.