Worked on #417, needs testing