refactoring wps's alg