refactored serve assignement function