Use long instead of int for iteration. Minor optimisations.