fixed function scope issue