finished code for server