Updated ModelThread function