Added tests & fixed conceptual bug identified by ichiwa on reddit.