more fixes; now everything seems to work the same way as the C++ example