temporary fix to printing the results of p_data and small fixes in p_data code logic.