Fixing javascript errors