Added more code and comments
Finished adding code from annyang.js