Code for rural cage from google code by Jay Chen