reorganized js and added comments