This seems duplicated from above... can you extract into a function?