Refactor run loop and add specs.