Bug fixes to js