Refactor and Range Optimization

Submitted to SPOJ with a 0.03 s reduction in execution speed!