move server code into app folder
fix server references
fix references, refactor a bit, and add more comments