refactored model code