Complete rewrite in Python
Removed old C copy