fix javascript flaws