optimise loops for performance
reduce function call overheads