Clean up some duplicated code