fixed some bugs, changed to a separate js