Python version added; Old C version rewritten.