more js fixes and code cleanup