reorganize javascript, and minor fixes