Fixing issues with javascript