This is a method that could benefit from some comments - for someone trying to debug, or quickly grok what's going on, this is a lot of code to slog through.