Work on #546, needs testing