Sam here - can we refactor the next couple of lines in a separate function?