completed replication of boyd of Python implementation in JS
Cleaned up test code