Some optimisation/refactoring using stdlib's functions