Bug fixes in models.py and util.py