refactored some codes after adding models associations