Consolidate python code


This is a rebase of #23