Take a look at `Kernel.destructure/2`. It may help you clean up some of this code or remove some of the duplication.