Rotating Around EyePoints

I’m using gluLookAt, and adding the eyepoint to the lookAt point, then I multiplied the lookAt point like it would have been if it was multiplied by rotation matrix. And it works however at times it spins around the eyepoint and then kind of goes back the same way? Anyone have any idea why this would happen.
Here’s the code for it.
void Viewpoint::rotateLocalViewCW()
GLdouble xPrime, newX;
GLdouble zPrime, newZ;

 xPrime = atPointX + viewerX;
 zPrime = atPointZ + viewerZ;
 newX = (xPrime * COS20) + (zPrime * SINP20);
newZ = (xPrime * SINP20 * -1) + (zPrime * COS20);

atPointX = newX - viewerX;
atPointZ = newZ - viewerZ;

As I said this works most of the time except I’ve noticed it sometimes doesnt work when I’m near the edge of my scene.
Anyone ever have this problem?