Cleanup and modularize the pymix code