Fixed the Javascript function