Refactor server into struct and methods