Fix/refactor upgrade procedure and tests

Still some cases to be covered in the tests