This is a big one! I'd like to break this up into several smaller methods, that should help with testing, maintenance and extensibility in the future. I'll leave some comments about different sections where we could start.