better working code which helped me identify the large bug that is issue #2
This code still suffers from that issue however and doesn't pass tests