Variables scoping corrected.