slightly cleaned up model code