tidy code and improve stability.