added comments and modularization to server