refactoring stages from functions to objects