Updated to function instead of sub