Edited JavaScript to resolve a small malfunction