Refactor Cython implementation

Replace singleton pattern with just using straight functions.