improved debug
fixed variable ambiguity
improved debug