minor modifications to v2, and new version using methods in v3.