Refactored model code to server