Refactor into setup.py compatible module