Lag can be addressed, too.. :> There's usually some inefficiencies sneak into the algorithm of whatever you are doing, plus there's always options like local variables (which I note you are already using), avoiding expensive operations like math.sqrt (heh, squirt... actually it stands for square root), etc.
Give it some thorough testing when you're done, and if it's too laggy then we can help with that as well.. :>