Fix function run-time errors