restructured server.js with binary routing function. can be refactored to lower size