Replace instruction refactoring and tests