Procedure WR + a lot of refactoring