Refactor and add comments to request-handler.js