Correcting Javascript errors and separating Javascript from HTML