small fixes and js refactoring