nit: This seems to be the same code as line 184. You can factor out into a helper function to be more DRY if you like.