refactored into module. Still not normalizing P