fix ws close error
change code structure