OK I've rearranged the method and beefed up the comments. New commit coming shortly.