This block belongs in a separate function, IMO.

After that, looks good to merge.