Internal improvements, some error checking. Removed dependency on LuaMath (that was just for paths)