Fixed a small bug in model

Not checking for value of res before using it, fixed now