Refactored to run from main