model cleanup code - thanks @cyli