fix bug and simplify the structure