some minor edit and optimisation