Function is now working