Added missing brackets and optimised JS for better compatibility.