fixed bug where p was not initialized