modified to make server code a module called from index