some code beautifying and reconstruction