Small optimizations. Added some locals, and changed from colon syntax to local function syntax.