Introduced server states and refactore