libpfrng: major code refactor