Trying to get this working a bit more robustly