Good idea, I've made an update and additionally factored out the duplicate code to a function.