Python Port: Bug fixes

Various bugs that I needed to fix in order to use the Python Port.