Refactored code into the models for better organization