restructured code. Now not really just a server!