Optimized code for reverse address ruby app (reviewed by Udit).