trying to fix variable scope issue