restructed code to be in server structure