revised to handle pcode