fixed another bug
fixed bigs by restructuring code