Figure 4 Server-side Code Done