Small optimization. Moved code executed 3 times into one method to help compressing and jit compilation