messy solution that runs in about 30s