move function to avoid closure issues