Implements #1328 and #1327