add some log and clean a little bit of code