Separated JavaScript and Fixed some Bugs