Fixed your code

got rid of all that nasty python and went with a working implementation, even has bonus emacs if you are so inclined