Refactored and commented server controller