minor fix and code optimisation