refactoring genPercept, still needs review