refactor run method to functions as it's going to be used in more places