Update model.py

Edited it so that it was closer to my current version (it's more robust and also easier to use)