refactor signature generate algorithm