Can we combine this with the above to avoid the duplicated code?