Refactor upgrade step and add tests