Updated PRE code.... fixing bugs in the process