Move functionality from run to helper functions.