Fixed closing bug in JS