Please fix this code up as per my request to extract this out into a function.