Not super happy with this implementation but it works