More work on python code. Not finished yet.