refactored some model code