Tidied up some repeated code into a helper