Refactored code and fixed bugs on PReg initialization.