Javascript bugfixes

- If a javascript variable is null, not try and use it