Refactor communication to server