simplify and add some debug