Merged Nate's and Ben's code. Ian's is next (shudders).