this works, but it could use a refactor … it's not DRY and it's super long