fixed scope null ref bug