trying to fix function scoping issue