Implement PRF, fix some bugs