Refactor by using instance variables instead of passing around some variables.