merged #501 to v4branch as well