Index: branches/eam_branches/ipp-20140226/psphot/src/psphotApResid.c
===================================================================
--- branches/eam_branches/ipp-20140226/psphot/src/psphotApResid.c	(revision 36620)
+++ branches/eam_branches/ipp-20140226/psphot/src/psphotApResid.c	(revision 36621)
@@ -214,5 +214,5 @@
 
         // XXX make this user-configurable?
-        if (source->psfMagErr > 0.01) continue;
+        if (source->psfMagErr > 0.03) continue;
 
         // aperture residual for this source
@@ -267,10 +267,11 @@
 
     // set the max order (0 = constant) which the number of psf stars can support:
-    // rule of thumb: require 3 stars per 'cell' (order+1)^2
+    // we require only 3 stars for n = 0, increase stars / cell for higher order
     int MaxOrderForStars = 0;
-    if (Npsf >= 12) MaxOrderForStars = 1; // 4 cells
-    if (Npsf >= 27) MaxOrderForStars = 2; // 9 cells
-    if (Npsf >= 48) MaxOrderForStars = 3; // 16 cells
-    if (Npsf >  75) MaxOrderForStars = 4; // 25 cells
+    if (Npsf >=  16) MaxOrderForStars = 1; // 4 cells
+    if (Npsf >=  54) MaxOrderForStars = 2; // 9 cells
+    if (Npsf >= 128) MaxOrderForStars = 3; // 16 cells
+    if (Npsf >= 300) MaxOrderForStars = 4; // 25 cells
+    if (Npsf >  576) MaxOrderForStars = 5; // 36 cells
 
     pmTrend2DMode mode = PM_TREND_MAP;
Index: branches/eam_branches/ipp-20140226/psphot/src/psphotChoosePSF.c
===================================================================
--- branches/eam_branches/ipp-20140226/psphot/src/psphotChoosePSF.c	(revision 36620)
+++ branches/eam_branches/ipp-20140226/psphot/src/psphotChoosePSF.c	(revision 36621)
@@ -399,5 +399,5 @@
     char *modelName = pmModelClassGetName (psf->type);
     psLogMsg ("psphot.pspsf", PS_LOG_WARN, "select psf model: %f sec\n", psTimerMark ("psphot.choose.psf"));
-    psLogMsg ("psphot.pspsf", PS_LOG_INFO, "psf model %s, ApResid: %f +/- %f\n", modelName, psf->ApResid, psf->dApResid);
+    psLogMsg ("psphot.pspsf", PS_LOG_INFO, "psf model %s, ApResid: %f +/- %f (%d x %d model)\n", modelName, psf->ApResid, psf->dApResid, psf->trendNx, psf->trendNy);
 
     psFree (options);
Index: branches/eam_branches/ipp-20140226/psphot/src/psphotLensing.c
===================================================================
--- branches/eam_branches/ipp-20140226/psphot/src/psphotLensing.c	(revision 36620)
+++ branches/eam_branches/ipp-20140226/psphot/src/psphotLensing.c	(revision 36621)
@@ -158,5 +158,5 @@
 
         // XXX make this user-configurable?
-        if (source->psfMagErr > 0.01) continue;
+        if (source->psfMagErr > 0.03) continue;
 
         // aperture residual for this source
@@ -192,10 +192,11 @@
 
     // set the max order (0 = constant) which the number of psf stars can support:
-    // rule of thumb: require 3 stars per 'cell' (order+1)^2
+    // we require only 3 stars for n = 0, increase stars / cell for higher order
     int LensingTrendOrder = 0;
-    if (Npsf >= 12) LensingTrendOrder = 1; // 4 cells
-    if (Npsf >= 27) LensingTrendOrder = 2; // 9 cells
-    if (Npsf >= 48) LensingTrendOrder = 3; // 16 cells
-    if (Npsf >  75) LensingTrendOrder = 4; // 25 cells
+    if (Npsf >=  16) LensingTrendOrder = 1; // 4 cells
+    if (Npsf >=  54) LensingTrendOrder = 2; // 9 cells
+    if (Npsf >= 128) LensingTrendOrder = 3; // 16 cells
+    if (Npsf >= 300) LensingTrendOrder = 4; // 25 cells
+    if (Npsf >  576) LensingTrendOrder = 5; // 36 cells
 
     pmTrend2DMode mode = PM_TREND_MAP;
@@ -217,4 +218,6 @@
     }
 
+    psLogMsg ("psphot.lensing", PS_LOG_DETAIL, "generate lensing maps using %d objects (%d x %d grid)\n", Npsf, Nx, Ny);
+
     // XXX allow user to set this optionally?
     psStats *stats = psStatsAlloc (PS_STAT_SAMPLE_MEDIAN | PS_STAT_SAMPLE_STDEV);
@@ -249,9 +252,9 @@
     for (int i = 0; i < sources->n; i++) {
         source = sources->data[i];
-
-	pmModel *model = source->modelPSF;
-
-	float xPos = model->params->data.F32[PM_PAR_XPOS];
-	float yPos = model->params->data.F32[PM_PAR_YPOS];
+	pmPeak *peak = source->peak;
+	if (!peak) continue;
+
+	float xPos = peak->xf;
+	float yPos = peak->yf;
 
 	if (!source->lensingPSF) {
@@ -283,5 +286,32 @@
     }
 
-    psLogMsg ("psphot.lensing", PS_LOG_DETAIL, "calculate lensing parameters for %d objects\n", (int) sources->n);
+    psFree (trendX11sm);
+    psFree (trendX12sm);
+    psFree (trendX22sm);
+    psFree (trend_e1sm);
+    psFree (trend_e2sm);
+	              
+    psFree (trendX11sh);
+    psFree (trendX12sh);
+    psFree (trendX22sh);
+    psFree (trend_e1sh);
+    psFree (trend_e2sh);
+
+    psFree (psfX11sm);
+    psFree (psfX12sm);
+    psFree (psfX22sm);
+    psFree (psf_e1sm);
+    psFree (psf_e2sm);
+    psFree (psfX11sh);
+    psFree (psfX12sh);
+    psFree (psfX22sh);
+    psFree (psf_e1sh);
+    psFree (psf_e2sh);
+    psFree (xPos    );
+    psFree (yPos    );
+
+    psFree (stats);
+
+    psLogMsg ("psphot.lensing", PS_LOG_DETAIL, "calculate lensing parameters for %d objects: %f sec\n", (int) sources->n, psTimerMark ("psphot.lensing"));
 
     return true;
