Fixed minor variable scope issues