Small bugfixes in .js code

Now this works fully ok, without any errors =)