Added debug mode and changed polygon splitting algorithm