clean up, add comments, improve program flow to ease app.js laod