Refactor to use functions in run, struct for settings, more