Original Python functions
Switched to Cython