fixed dictionary size changes during model initialization
lots of python 3 compatibility fixes