Fixing JS function