merged @Copper-Head's work from model branch