working on #1571. almost done, needs a few more changes