Fixed #577
Work on #855; needs testing