adding changes from Gary's comments, still in debugging process