refactoring python stuff for easier querying