hmmm, well, after the width and height has been released, the script checks if x2/y2 < x/y now,
I'm not sure, but try putting the width and height part after the that little check.
if ( x2 < x ) then
local tempx = x2
x2 = x
x = tempx
end
if ( y2 < y ) then
local tempy = y2
y2 = y
y = tempy
end
local width, height = math.abs ( x2 - x ), math.abs ( y2 - y )