refactor into python module