Refactored, now runs as console standalone.