Adapted javascript