Optimisation: was checking i against the length of the string twice per iter. Will now break part way through the loop allowing for only one check of i against the length