py: refactored code into modules