Performance problems from issue #22

Applying patch suggested on issue #22. Tests using the GEM.inp file suggest that performance is improved using this patch on different CPU architectures with gcc compiler.