feed-back on camera rotate script

I have been working on a fairly simple camera rotate script to sharpen up my skills over the summer and prepare my for an upcoming project. Most of the code for said project has been gleamed from this tutorial http://www.youtube.com/watch?v=ChOf-pCUSAs, with code adjusted to fit my needs. The resulting script works, but is rather jerky and unusable. I have been tinkering with it for awhile but wanted to post it here and see if anyone and any suggestions/criticism on how to make it smoother.

Attachments

cameraRotateLecture_03.blend (487 KB)

Take a look at this code, it may give you some ideas on how to reduce the stuttering;

#Raider's Mouselook for 2.62
#By Aiden Sibley

#A note on axises:
# The camera orbits side-to-side around its Y axis and up/down around its X axis.
# These axises are appropriate when applied to camera objects, but if you want to
# apply the mouselook to another object (for instance, an empty, when making an
# over-the-shoulder view), you can change the axises by fiddling with the axis 
# arguments to the the Matrix.Rotation(angle, size, axis) functions.

import math
import bge
from mathutils import *


sensitivity = 0.001            #Sensitivity of mouselook
xlimit = math.radians(0)        #Up-down viewing angle limit


own = bge.logic.getCurrentController().owner
mouse = own.sensors['mouse']


#Get the screen's middle point and the mouse position
mid = Vector([200,200]) #Substituted to sidestep issues with odd-number dimensions. Just don't use a screen smaller than 200*200.
mpos = Vector(mouse.position)


#Initialisation. (ml stands for mouselook)
if not "ml_angle" in own:
    own["ml_start_mat"] = own.localOrientation.copy() #Record the initial orientation of the object
    own["ml_angle"] = Vector([0,0])
    mpos = mid.copy() #Ignore the mouse position on the first frame to avoid a sudden jerk.
    bge.render.showMouse(0)


#Get mouse position offset from the middle of the screen, apply sensitivity, and add to ml_angle.
if (("mouselook_active" in own and own["mouselook_active"]) or not "mouselook_active" in own):
    own["ml_angle"] += (mpos - mid)*sensitivity


#Limit vertical viewing angle.
own["ml_angle"][1] = max(min(own["ml_angle"][1],xlimit),-xlimit)


#Generate rotation matrices from angles.
xmat = Matrix.Rotation(-own["ml_angle"][1],3,"X") #This is up/down
zmat = Matrix.Rotation(-own["ml_angle"][0],3,"Z") #This is left/right


#Combine and add to the initial orientation.
own.localOrientation = own["ml_start_mat"]*zmat*xmat


#Set mouse position to the middle of the screen.
bge.render.setMousePosition(int(mid[0]),int(mid[1]))