Refactor run logic