refactor in the rest plugin