[bug981357] - wrapped in function to keep variables local