Reverted to earlier JS code