Some small optimizations and js cleanup