Final(?) version of node js version of this. Maybe I'll reimplement in python?