setup.py fixes and refactoring