Refactored with __main__ to localize variables, run code only when run (not imported)