Gpii 947

http://issues.gpii.net/browse/GPII-947
I'm not really sure what this function is doing. Can you provide comments. This may be something that should be broken down into separate functions. Ideally functions will do only one thing.