De-duplicate some code