I would like to make this nicer, but it's a bit tricky