Fix function so it works