Initial code for the Python rewrite